package com.weixin.paleituo.view;

import android.content.Context;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.PopupWindow;

import com.weixin.paleituo.R;
import com.weixin.paleituo.base.BaseActivity;
import com.weixin.paleituo.bean.AreaInfoBean;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 购物列表区域选择弹框
 *
 * @author fengzhen
 * @version v1.0, 2018/3/29
 * @deprecated 废弃，popupwindow中获取不到fragmentManager
 */
@Deprecated
public class AreaSelectorPopWindow extends PopupWindow {

    @BindView(R.id.frame_close)
    FrameLayout mFrameClose;
    @BindView(R.id.view_pager_pop_window_area_selector)
    ViewPager mViewPagerPopWindowAreaSelector;

    private ArrayList<AreaInfoBean> mAddressList = new ArrayList<>();
    private AreaPagerAdapter mAreaPagerAdapter;
    private int[] mRanks = {1, 2, 3};

    public AreaSelectorPopWindow(Context context, List<AreaInfoBean> areaList) {
        super(context);
        this.mAddressList.addAll(areaList);
        initWindow(context);
    }

    private void initWindow(Context context) {
        View inflate = LayoutInflater.from(context).inflate(R.layout.pop_window_area_selector, null);
        setContentView(inflate);
        ButterKnife.bind(this, inflate);
        setWidth(ViewGroup.LayoutParams.MATCH_PARENT);
        setHeight(ViewGroup.LayoutParams.MATCH_PARENT);
        // 去边框问题
        setBackgroundDrawable(null);
        setFocusable(true);

        mAreaPagerAdapter = new AreaPagerAdapter(((BaseActivity) context).getSupportFragmentManager());
        mViewPagerPopWindowAreaSelector.setAdapter(mAreaPagerAdapter);

    }

    @OnClick(R.id.frame_close)
    public void onClick() {
        dismiss();
    }

    public class AreaPagerAdapter extends FragmentPagerAdapter {

        public AreaPagerAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int position) {
//            return ShippingAreaFragment.newInstance(mAddressList, mRanks[position]);
            return null;
        }

        @Override
        public int getCount() {
            return mRanks.length;
        }
    }
}
